package com.coolw.log4j2.mask.log;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.hutool.core.data.MaskingUtil;

import java.util.function.Function;

/**
 * 脱敏规则定义
 *
 * @author coolw
 * @date 2024/4/22 19:54
 */
@Getter
@AllArgsConstructor
public enum MaskRuleEnum {

    NONE("不脱敏", data -> data),
    ID_CARD("身份证号", MaskRuleEnum::maskIdCard),
    MOBILE("手机号", MaskRuleEnum::maskMobile),
    NAME("姓名", MaskRuleEnum::maskName),
    BANK_CARD("银行卡号", MaskRuleEnum::maskBankCard);

    private final String ruleName;

    private final Function<String, String> maskFunc;

    public static String maskIdCard(String idCard) {
        return MaskingUtil.idCardNum(idCard, 4, 6);
    }

    public static String maskMobile(String mobile) {
        return MaskingUtil.mobilePhone(mobile);
    }

    public static String maskName(String name) {
        return MaskingUtil.chineseName(name);
    }

    public static String maskBankCard(String bankCard) {
        return MaskingUtil.bankCard(bankCard).replace(" ", "");
    }
}
